home *** CD-ROM | disk | FTP | other *** search
/ Usenet 1993 July / InfoMagic USENET CD-ROM July 1993.ISO / sources / x / volume13 / xmeter / patch6 next >
Encoding:
Internet Message Format  |  1991-06-18  |  54.2 KB

  1. Path: uunet!uunet!munnari.oz.au!metro!cluster!swift!sunaus.oz!newstop!exodus!rand.org
  2. From: bobs@rand.org (Rober Schwartzkopf)
  3. Newsgroups: comp.sources.x
  4. Subject: v13i056: xmeter, Patch6, Part01/01
  5. Message-ID: <15395@exodus.Eng.Sun.COM>
  6. Date: 18 Jun 91 06:42:17 GMT
  7. References: <csx-13i056-xmeter@uunet.UU.NET>
  8. Sender: news@exodus.Eng.Sun.COM
  9. Lines: 1967
  10. Approved: argv@sun.com
  11.  
  12. Submitted-by: Rober Schwartzkopf <bobs@rand.org>
  13. Posting-number: Volume 13, Issue 56
  14. Archive-name: xmeter/patch6
  15. Patch-To: xmeter: Volume 9, Issue 59 (9/28/90)
  16.  
  17. This is xmeter patchlevel 6.  Changes since the previous release
  18. include new option (-v) to print xmeter version, defstat option to
  19. change the default statistic to be watched, clearing of stripchart
  20. widgets when watched stat is changed, and better handling of dead
  21. hosts, as well as a couple of minor bug fixes.
  22.  
  23. Bob Schwartzkopf (bobs@rand.org)
  24.  
  25. #! /bin/sh
  26. # This is a shell archive.  Remove anything before this line, then unpack
  27. # it by saving it into a file and typing "sh file".  To overwrite existing
  28. # files, type "sh file -c".  You can also feed this as standard input via
  29. # unshar, or by typing "sh <file", e.g..  If this archive is complete, you
  30. # will see the following message at the end:
  31. #        "End of shell archive."
  32. # Contents:  patchlevel.h README Imakefile xmeter.c xmeter.man
  33. #   XMeter.ad
  34. # Wrapped by root@boris on Mon Jun  3 15:27:22 1991
  35. PATH=/bin:/usr/bin:/usr/ucb ; export PATH
  36. if test -f 'patchlevel.h' -a "${1}" != "-c" ; then 
  37.   echo shar: Will not clobber existing file \"'patchlevel.h'\"
  38. else
  39. echo shar: Extracting \"'patchlevel.h'\" \(21 characters\)
  40. sed "s/^X//" >'patchlevel.h' <<'END_OF_FILE'
  41. X#define PATCHLEVEL 6
  42. END_OF_FILE
  43. if test 21 -ne `wc -c <'patchlevel.h'`; then
  44.     echo shar: \"'patchlevel.h'\" unpacked with wrong size!
  45. fi
  46. # end of 'patchlevel.h'
  47. fi
  48. if test -f 'README' -a "${1}" != "-c" ; then 
  49.   echo shar: Will not clobber existing file \"'README'\"
  50. else
  51. echo shar: Extracting \"'README'\" \(1879 characters\)
  52. sed "s/^X//" >'README' <<'END_OF_FILE'
  53. Xxmeter displays a histogram of data returned by rstat(3).  It can be
  54. Xtold to monitor multiple hosts, or to monitor multiple statistics on the
  55. Xsame host.
  56. X
  57. XAuthor: Bob Schwartzkopf (bobs@rand.org)
  58. X    The RAND Corporation
  59. X    1700 Main Street
  60. X    Santa Monica, CA 90406-2138
  61. X
  62. XEdit history
  63. X
  64. XPatchlevel 6
  65. X    - Clear stripcharts when monitored statistic is changed.
  66. X    - Allow setting of monitored stat in .Xdefaults.
  67. X    - Added -v option to display version number.
  68. X    - Fork new process to wait for dead host to come back up.
  69. X
  70. XPatchlevel 5
  71. X    - Put explict closes of sockets back in after clnt_destroy().
  72. X      Apparently some versions of clnt_destroy don't close the
  73. X      socket.
  74. X    - Minor changes to XMeter.ad.
  75. X
  76. XPatchlevel 4
  77. X    - Allow user to specify foreground, border, internal border and
  78. X      highlight color for each level.
  79. X    - Fixed bug in determining width/height of form widget.
  80. X    - Allow user to specify label foreground and background colors
  81. X      independently of stripcharts.
  82. X    - Made all colors either class Foreground or Background, should
  83. X      simplify .Xdefaults files.
  84. X
  85. XPatchlevel 3
  86. X    - Added "cols" and "rows" options, allows rectangular
  87. X      layout of graphs.  Removed "orientation" option.
  88. X    - Backgrounds of stripcharts can now be set to user specified
  89. X      bitmaps with "*Bitmap" resources.
  90. X    - Added op, wp, ep and fp options, which takes a program name as an
  91. X      argument.  When a graph enters state OK, WARN, ERROR or FATAL, the
  92. X      specified program is invoked.
  93. X    - Added menus which allow the monitored statistic to be changed
  94. X      on the fly.
  95. X
  96. XPatchlevel 2
  97. X    - Changed resource name of paned widgets to host name.
  98. X    - Used actual time between rstat(3) calls instead of "update"
  99. X      interval for computing graph values.
  100. X    - Rewrote functions that return graph values.
  101. X    - Fixed divide by 0 errors in fcpu(), fsys() and fuser().
  102. X    - Use RSTATVERS_TIME instead of RSTATVERS.
  103. X
  104. XPatchlevel 1
  105. X    - Fixed memory leak.
  106. END_OF_FILE
  107. if test 1879 -ne `wc -c <'README'`; then
  108.     echo shar: \"'README'\" unpacked with wrong size!
  109. fi
  110. # end of 'README'
  111. fi
  112. if test -f 'Imakefile' -a "${1}" != "-c" ; then 
  113.   echo shar: Will not clobber existing file \"'Imakefile'\"
  114. else
  115. echo shar: Extracting \"'Imakefile'\" \(369 characters\)
  116. sed "s/^X//" >'Imakefile' <<'END_OF_FILE'
  117. X       INCLUDES = -I$(TOP) -I$(TOP)/X11
  118. X        DEPLIBS = XawClientDepLibs
  119. XLOCAL_LIBRARIES = XawClientLibs
  120. X  SYS_LIBRARIES = -lrpcsvc
  121. X           SRCS = xmeter.c
  122. X           OBJS = xmeter.o
  123. X      SHARS = patchlevel.h README Imakefile xmeter.c xmeter.man XMeter.ad
  124. X
  125. XComplexProgramTarget(xmeter)
  126. XInstallAppDefaults(XMeter)
  127. X
  128. Xxmeter.shar:    $(SHARS)
  129. X    shar -o xmeter.shar $(SHARS)
  130. END_OF_FILE
  131. if test 369 -ne `wc -c <'Imakefile'`; then
  132.     echo shar: \"'Imakefile'\" unpacked with wrong size!
  133. fi
  134. # end of 'Imakefile'
  135. fi
  136. if test -f 'xmeter.c' -a "${1}" != "-c" ; then 
  137.   echo shar: Will not clobber existing file \"'xmeter.c'\"
  138. else
  139. echo shar: Extracting \"'xmeter.c'\" \(33499 characters\)
  140. sed "s/^X//" >'xmeter.c' <<'END_OF_FILE'
  141. X/*
  142. X * xmeter.c - Display histogram of rstat(3) output for multiple hosts.
  143. X *
  144. X * Author: Bob Schwartzkopf, The RAND Corporation
  145. X *
  146. X * Suggestions for improvements and bug fixes can be sent to "bobs@rand.org".
  147. X * As my schedule permits I'll try to incorporate them.
  148. X */
  149. X
  150. X#ifndef lint
  151. Xstatic char    *RCSid="$Header: /usr/rand/src/bin/xmeter/RCS/xmeter.c,v 1.7 1991/06/03 22:21:43 root Exp $";
  152. X#endif lint
  153. X
  154. X/*
  155. X * $Log: xmeter.c,v $
  156. X * Revision 1.7  1991/06/03  22:21:43  root
  157. X * Add -v option to print xmeter version number.
  158. X * Add defstat option.
  159. X * Add code to clear stripchart when watched stat is changed.
  160. X * When host is down fork process to wait for it to come up instead of
  161. X * having toplevel process wait for timeouts.
  162. X *
  163. X * Revision 1.6  90/09/28  20:32:34  root
  164. X * Add explicit closes of sockets back in, apparently some versions of
  165. X * clnt_destroy() don't do it automatically.
  166. X * 
  167. X * Revision 1.5  90/09/18  20:47:03  root
  168. X * Allow user specification of foreground colors.
  169. X * 
  170. X * Revision 1.4  90/08/20  14:18:01  root
  171. X * Added menus, column and row options, background bitmaps, and user
  172. X * specifiable programs to be invoked when graphs change state.
  173. X * 
  174. X * Revision 1.3  90/06/07  16:17:06  bobs
  175. X * Removed "retries".
  176. X * Changed name of paned widgets to host name displayed in that widget.
  177. X * Used actual time between rstat calls instead of "update" interval in
  178. X * computing rates in functions that return values to stripchart widgets.
  179. X * Removed "ost" variable, rewrote functions that return values to
  180. X * stripcharts.
  181. X * Fixed bug in fsys, fcpu and fuser that could cause divide by 0 errors.
  182. X * Fixed rpc timeout handling in getmeter and getport.
  183. X * Use RSTATVERS_TIME instead of RSTATVERS, which isn't defined in SunOS 4.1.
  184. X * 
  185. X * Revision 1.2  90/05/04  12:31:52  bobs
  186. X * Fix memory leak in getport().  Wasn't freeing resources allocated by
  187. X * clntudp_create when clnt_call failed.  Also removed explicit calls
  188. X * to close sockets since clnt_destroy() does this.
  189. X * 
  190. X * Revision 1.1  90/04/30  14:33:59  bobs
  191. X * Initial revision
  192. X * 
  193. X */
  194. X
  195. X#include <stdio.h>
  196. X#include <sys/time.h>
  197. X#include <sys/param.h>
  198. X#include <sys/socket.h>
  199. X#include <sys/dk.h>
  200. X#include <signal.h>
  201. X#include <netdb.h>
  202. X#include <rpc/rpc.h>
  203. X#include <rpc/pmap_prot.h>
  204. X#include <rpcsvc/rstat.h>
  205. X#include <X11/Xlib.h>
  206. X#include <X11/Intrinsic.h>
  207. X#include <X11/StringDefs.h>
  208. X#include <X11/Xatom.h>
  209. X#include <X11/Shell.h>
  210. X#include <X11/Xaw/Cardinals.h>
  211. X#include <X11/Xaw/Form.h>
  212. X#include <X11/Xaw/StripChart.h>
  213. X#include <X11/Xaw/SimpleMenu.h>
  214. X#include <X11/Xaw/MenuButton.h>
  215. X#include <X11/Xaw/SmeBSB.h>
  216. X#include <X11/Xaw/Paned.h>
  217. X#include <X11/Xmu/Xmu.h>
  218. X#include "patchlevel.h"
  219. X
  220. X#define MAJORVERSION    1
  221. X#define DMSG        "down"
  222. X#define OK        0
  223. X#define WARN        1
  224. X#define ERROR        2
  225. X#define FATAL        3
  226. X#define MAXBACKS    (FATAL+1)
  227. X#define STATMENU    "statmenu"
  228. X#ifndef FSCALE
  229. X#define FSCALE        (1 << 8)
  230. X#endif
  231. X
  232. X/*
  233. X * There is one METER structure per strip chart.  If multiple stats
  234. X * on a single host are being watched we save rstatd calls by sharing
  235. X * part of this structure (SHMETER) between the different meters watching
  236. X * the same host.
  237. X */
  238. Xtypedef struct _shmeter {
  239. X    char        *name;    /* Host name                */
  240. X    struct sockaddr_in    addr;
  241. X    CLIENT        *clnt;
  242. X    int            s;    /* Socket                */
  243. X    struct statstime    st[2];    /* Keep last 2 stats to compute diffs    */
  244. X    int            idx;    /* Index into st array            */
  245. X    int            refcnt;    /* Meters sharing this structure    */
  246. X    int            curcnt;    /* Meters who've displayed current data    */
  247. X    int            first;    /* TRUE when only 1 rstat has been done    */
  248. X    int            pid;    /* Pid of proc waiting for host        */
  249. X    struct _shmeter    *nxt;    /* Link these together            */
  250. X} SHMETER;
  251. X
  252. Xtypedef struct _meter {
  253. X    char        *label;
  254. X    int            stat;        /* Which stat to watch        */
  255. X    Widget        pdwidget;    /* Paned widget            */
  256. X    Widget        mbwidget;    /* MenuButton widget        */
  257. X    Widget        scwidget;    /* StripChart widget        */
  258. X    int            oldstate;    /* Save state so know when to    */
  259. X                    /* change backgrounds        */
  260. X    SHMETER        *sh;        /* Shared info            */
  261. X    Pixmap        pm;        /* Current background pixmap    */
  262. X    int            oldjumpscroll;    /* Old jumpscroll value        */
  263. X    struct _meter    *nxt;
  264. X} METER;
  265. X
  266. X/*
  267. X * There is a STATDATA structure for each statistic that can be monitored.
  268. X */
  269. Xtypedef struct {
  270. X    int        scale;        /* Each stat is scaled            */
  271. X    int        (*val)();    /* Function that computes this stat    */
  272. X    char    *name;        /* Name of stat for menu widget        */
  273. X} STATDATA;
  274. X
  275. X/*
  276. X * xmeter supports 4 background colors and pixmaps that it will switch
  277. X * between as a meter changes state, called OK, WARN, ERROR and FATAL.
  278. X * The background bitmaps are stored in BITMAP structures.
  279. X */
  280. Xtypedef struct {
  281. X  int        w;                /* Width of bitmap    */
  282. X  int        h;                /* Height of bitmap    */
  283. X  Pixmap    bm;                /* Bitmap        */
  284. X} BITMAP;
  285. X
  286. X/*
  287. X * Functions
  288. X */
  289. Xextern char    *malloc ();
  290. Xextern char    *index ();
  291. Xint        getstatus ();
  292. Xint        changestat ();
  293. Xint        selecthost ();
  294. Xint        freechild ();
  295. XMETER        *initmeter ();
  296. Xint        fcoll (), fcpu (), fierr (), fintr (), fipkt (), fload ();
  297. Xint        foerr (), fopkt (), fpage (), fpgpgin (), fpgpgout ();
  298. Xint        fpswpin (), fpswpout (), fswt (), fsys (), fuser ();
  299. X
  300. XSTATDATA        sd[] = {
  301. X#define S_COLL        0
  302. X  {1, fcoll, "coll"},
  303. X#define S_CPU        S_COLL+1
  304. X  {1, fcpu, "cpu"},
  305. X#define S_IERR        S_CPU+1
  306. X  {1, fierr, "ierr"},
  307. X#define S_INTR        S_IERR+1
  308. X  {1, fintr, "intr"},
  309. X#define S_IPKT        S_INTR+1
  310. X  {1, fipkt, "ipkt"},
  311. X#define S_LOAD        S_IPKT+1
  312. X  {1, fload, "load"},
  313. X#define S_OERR        S_LOAD+1
  314. X  {1, foerr, "oerr"},
  315. X#define S_OPKT        S_OERR+1
  316. X  {1, fopkt, "opkt"},
  317. X#define S_PAGE        S_OPKT+1
  318. X  {1, fpage, "page"},
  319. X#define S_PGPGIN    S_PAGE+1
  320. X  {1, fpgpgin, "pgpgin"},
  321. X#define S_PGPGOUT    S_PGPGIN+1
  322. X  {1, fpgpgout, "pgpgout"},
  323. X#define S_PSWPIN    S_PGPGOUT+1
  324. X  {1, fpswpin, "pswpin"},
  325. X#define S_PSWPOUT    S_PSWPIN+1
  326. X  {1, fpswpout, "pswpout"},
  327. X#define S_SWT        S_PSWPOUT+1
  328. X  {1, fswt, "swt"},
  329. X#define S_SYS        S_SWT+1
  330. X  {1, fsys, "sys"},
  331. X#define S_USER        S_SYS+1
  332. X  {1, fuser, "user"},
  333. X};
  334. X#define DEFSTATNAME    "load"
  335. X#define MAXSTAT        (sizeof (sd) / sizeof (STATDATA))
  336. X#define MAXSTATNAME    10        /* Max length of stat name    */
  337. X
  338. Xstatic char        *progname;
  339. XPixel            back[MAXBACKS];        /* Meter backgrounds    */
  340. XPixel            fore[MAXBACKS];        /* Meter foregrounds    */
  341. XPixel            hl[MAXBACKS];        /* Meter highlights    */
  342. XPixel            bd[MAXBACKS];        /* Meter borders    */
  343. XPixel            ibd[MAXBACKS];        /* Meter internal bds    */
  344. XPixel            lback[MAXBACKS];    /* Label backgrounds    */
  345. XPixel            lfore[MAXBACKS];    /* Label foregrounds    */
  346. XBITMAP            bitmap[MAXBACKS];    /* Stripchart bg pixmaps*/
  347. XPixmap            bitmapdef = XtUnspecifiedPixmap;
  348. Xint            warnLevel;        /* Warning level    */
  349. Xint            errorLevel;        /* Error level        */
  350. Xstatic struct timeval    ptto = {0, 0};        /* RPC timeout interval    */
  351. Xstatic struct timeval    tto = {0, 0};        /* Total timeout    */
  352. Xstatic SHMETER        *shmeters = NULL;    /* List of SHMETERs    */
  353. Xstatic METER        *selected;        /* Current meter    */
  354. Xstatic METER        *meterlist = NULL;    /* List of METERs    */
  355. Xint            columns;        /* Columns to display    */
  356. Xint            rows;            /* Rows    to display    */
  357. Xint            timeout;        /* RPC timeout        */
  358. Xint            retries;        /* RPC retries        */
  359. Xint            loadscaledef = FSCALE;    /* Scale for load ave.    */
  360. XBoolean            shortname;        /* Short hostname flag    */
  361. XString            prog[MAXBACKS];        /* Alert programs    */
  362. XString            defstat;        /* Default stat        */
  363. Xstatic XtResource    application_resources[] = {
  364. X    {"columns", "Columns", XtRInt, sizeof (int),
  365. X    (Cardinal) &columns, XtRString, "0"},
  366. X    {"defStat", "DefStat", XtRString, sizeof (char *),
  367. X    (Cardinal) &defstat, XtRString, DEFSTATNAME},
  368. X    {"errorBack", XtCBackground, XtRPixel, sizeof (Pixel),
  369. X    (Cardinal) &back[ERROR], XtRString, XtDefaultBackground},
  370. X    {"errorBd", XtCForeground, XtRPixel, sizeof (Pixel),
  371. X    (Cardinal) &bd[ERROR], XtRString, XtDefaultForeground},
  372. X    {"errorBitmap", XtCBitmap, XtRBitmap, sizeof (Pixmap),
  373. X    (Cardinal) &bitmap[ERROR].bm, XtRBitmap, (caddr_t) &bitmapdef},
  374. X    {"errorFore", XtCForeground, XtRPixel, sizeof (Pixel),
  375. X    (Cardinal) &fore[ERROR], XtRString, XtDefaultForeground},
  376. X    {"errorHl", XtCForeground, XtRPixel, sizeof (Pixel),
  377. X    (Cardinal) &hl[ERROR], XtRString, XtDefaultForeground},
  378. X    {"errorIbd", XtCForeground, XtRPixel, sizeof (Pixel),
  379. X    (Cardinal) &ibd[ERROR], XtRString, XtDefaultForeground},
  380. X    {"errorLevel", "ErrorLevel", XtRInt, sizeof (int),
  381. X    (Cardinal) &errorLevel, XtRString, "6"},
  382. X    {"errorProg", "Program", XtRString, sizeof (char *),
  383. X    (Cardinal) &prog[ERROR], XtRString, NULL},
  384. X    {"fatalBack", XtCBackground, XtRPixel, sizeof (Pixel),
  385. X    (Cardinal) &back[FATAL], XtRString, XtDefaultBackground},
  386. X    {"fatalBd", XtCForeground, XtRPixel, sizeof (Pixel),
  387. X    (Cardinal) &bd[FATAL], XtRString, XtDefaultForeground},
  388. X    {"fatalBitmap", XtCBitmap, XtRBitmap, sizeof (Pixmap),
  389. X    (Cardinal) &bitmap[FATAL].bm, XtRBitmap, (caddr_t) &bitmapdef},
  390. X    {"fatalFore", XtCForeground, XtRPixel, sizeof (Pixel),
  391. X    (Cardinal) &fore[FATAL], XtRString, XtDefaultForeground},
  392. X    {"fatalHl", XtCForeground, XtRPixel, sizeof (Pixel),
  393. X    (Cardinal) &hl[FATAL], XtRString, XtDefaultForeground},
  394. X    {"fatalIbd", XtCForeground, XtRPixel, sizeof (Pixel),
  395. X    (Cardinal) &ibd[FATAL], XtRString, XtDefaultForeground},
  396. X    {"fatalProg", "Program", XtRString, sizeof (char *),
  397. X    (Cardinal) &prog[FATAL], XtRString, NULL},
  398. X    {"lErrorBack", XtCBackground, XtRPixel, sizeof (Pixel),
  399. X    (Cardinal) &lback[ERROR], XtRString, XtDefaultBackground},
  400. X    {"lErrorFore", XtCForeground, XtRPixel, sizeof (Pixel),
  401. X    (Cardinal) &lfore[ERROR], XtRString, XtDefaultForeground},
  402. X    {"lFatalBack", XtCBackground, XtRPixel, sizeof (Pixel),
  403. X    (Cardinal) &lback[FATAL], XtRString, XtDefaultBackground},
  404. X    {"lFatalFore", XtCForeground, XtRPixel, sizeof (Pixel),
  405. X    (Cardinal) &lfore[FATAL], XtRString, XtDefaultForeground},
  406. X    {"lOkBack", XtCBackground, XtRPixel, sizeof (Pixel),
  407. X    (Cardinal) &lback[OK], XtRString, XtDefaultBackground},
  408. X    {"lOkFore", XtCForeground, XtRPixel, sizeof (Pixel),
  409. X    (Cardinal) &lfore[OK], XtRString, XtDefaultForeground},
  410. X    {"lWarnBack", XtCBackground, XtRPixel, sizeof (Pixel),
  411. X    (Cardinal) &lback[WARN], XtRString, XtDefaultBackground},
  412. X    {"lWarnFore", XtCForeground, XtRPixel, sizeof (Pixel),
  413. X    (Cardinal) &lfore[WARN], XtRString, XtDefaultForeground},
  414. X    {"okBack", XtCBackground, XtRPixel, sizeof (Pixel),
  415. X    (Cardinal) &back[OK], XtRString, XtDefaultBackground},
  416. X    {"okBd", XtCForeground, XtRPixel, sizeof (Pixel),
  417. X    (Cardinal) &bd[OK], XtRString, XtDefaultForeground},
  418. X    {"okBitmap", XtCBitmap, XtRBitmap, sizeof (Pixmap),
  419. X    (Cardinal) &bitmap[OK].bm, XtRBitmap, (caddr_t) &bitmapdef},
  420. X    {"okFore", XtCForeground, XtRPixel, sizeof (Pixel),
  421. X    (Cardinal) &fore[OK], XtRString, XtDefaultForeground},
  422. X    {"okHl", XtCForeground, XtRPixel, sizeof (Pixel),
  423. X    (Cardinal) &hl[OK], XtRString, XtDefaultForeground},
  424. X    {"okIbd", XtCForeground, XtRPixel, sizeof (Pixel),
  425. X    (Cardinal) &ibd[OK], XtRString, XtDefaultForeground},
  426. X    {"okProg", "Program", XtRString, sizeof (char *),
  427. X    (Cardinal) &prog[OK], XtRString, NULL},
  428. X    {"retries", "Retries", XtRInt, sizeof (int),
  429. X    (Cardinal) &retries, XtRString, "2"},
  430. X    {"rows", "Rows", XtRInt, sizeof (int),
  431. X    (Cardinal) &rows, XtRString, "0"},
  432. X    {"scaleColl", "ScaleColl", XtRInt, sizeof (int),
  433. X    (Cardinal) &sd[S_COLL].scale, XtRString, "1"},
  434. X    {"scaleCpu", "ScaleCpu", XtRInt, sizeof (int),
  435. X    (Cardinal) &sd[S_CPU].scale, XtRString, "20"},
  436. X    {"scaleIerr", "ScaleIerr", XtRInt, sizeof (int),
  437. X    (Cardinal) &sd[S_IERR].scale, XtRString, "1"},
  438. X    {"scaleIntr", "ScaleIntr", XtRInt, sizeof (int),
  439. X    (Cardinal) &sd[S_INTR].scale, XtRString, "50"},
  440. X    {"scaleIpkt", "ScaleIpkt", XtRInt, sizeof (int),
  441. X    (Cardinal) &sd[S_IPKT].scale, XtRString, "20"},
  442. X    {"scaleLoad", "ScaleLoad", XtRInt, sizeof (int),
  443. X    (Cardinal) &sd[S_LOAD].scale, XtRInt, (caddr_t) &loadscaledef},
  444. X    {"scaleOerr", "ScaleOerr", XtRInt, sizeof (int),
  445. X    (Cardinal) &sd[S_OERR].scale, XtRString, "1"},
  446. X    {"scaleOpkt", "ScaleOpkt", XtRInt, sizeof (int),
  447. X    (Cardinal) &sd[S_OPKT].scale, XtRString, "20"},
  448. X    {"scalePage", "ScalePage", XtRInt, sizeof (int),
  449. X    (Cardinal) &sd[S_PAGE].scale, XtRString, "10"},
  450. X    {"scalePgpgin", "ScalePgpgin", XtRInt, sizeof (int),
  451. X    (Cardinal) &sd[S_PGPGIN].scale, XtRString, "10"},
  452. X    {"scalePgpgout", "ScalePgpgout", XtRInt, sizeof (int),
  453. X    (Cardinal) &sd[S_PGPGOUT].scale, XtRString, "10"},
  454. X    {"scalePswpin", "ScalePswpin", XtRInt, sizeof (int),
  455. X    (Cardinal) &sd[S_PSWPIN].scale, XtRString, "1"},
  456. X    {"scalePswpout", "ScalePswpout", XtRInt, sizeof (int),
  457. X    (Cardinal) &sd[S_PSWPOUT].scale, XtRString, "1"},
  458. X    {"scaleSwt", "ScaleSwt", XtRInt, sizeof (int),
  459. X    (Cardinal) &sd[S_SWT].scale, XtRString, "30"},
  460. X    {"scaleSys", "ScaleSys", XtRInt, sizeof (int),
  461. X    (Cardinal) &sd[S_SYS].scale, XtRString, "20"},
  462. X    {"scaleUser", "ScaleUser", XtRInt, sizeof (int),
  463. X    (Cardinal) &sd[S_USER].scale, XtRString, "20"},
  464. X    {"shortName", "Shortname", XtRBoolean, sizeof (Boolean),
  465. X    (Cardinal) &shortname, XtRString, "False"},
  466. X    {"timeout", "Timeout", XtRInt, sizeof (int),
  467. X    (Cardinal) &timeout, XtRString, "5"},
  468. X    {"warnBack", XtCBackground, XtRPixel, sizeof (Pixel),
  469. X    (Cardinal) &back[WARN], XtRString, XtDefaultBackground},
  470. X    {"warnBd", XtCForeground, XtRPixel, sizeof (Pixel),
  471. X    (Cardinal) &bd[WARN], XtRString, XtDefaultForeground},
  472. X    {"warnBitmap", XtCBitmap, XtRBitmap, sizeof (Pixmap),
  473. X    (Cardinal) &bitmap[WARN].bm, XtRBitmap, (caddr_t) &bitmapdef},
  474. X    {"warnFore", XtCForeground, XtRPixel, sizeof (Pixel),
  475. X    (Cardinal) &fore[WARN], XtRString, XtDefaultForeground},
  476. X    {"warnHl", XtCForeground, XtRPixel, sizeof (Pixel),
  477. X    (Cardinal) &hl[WARN], XtRString, XtDefaultForeground},
  478. X    {"warnIbd", XtCForeground, XtRPixel, sizeof (Pixel),
  479. X    (Cardinal) &ibd[WARN], XtRString, XtDefaultForeground},
  480. X    {"warnLevel", "WarnLevel", XtRInt, sizeof (int),
  481. X    (Cardinal) &warnLevel, XtRString, "3"},
  482. X    {"warnProg", "Program", XtRString, sizeof (char *),
  483. X    (Cardinal) &prog[WARN], XtRString, NULL},
  484. X};
  485. Xstatic XrmOptionDescRec    options[] = {
  486. X    {"-cols",        "columns",        XrmoptionSepArg,    NULL},
  487. X    {"-ebd",        "errorBd",        XrmoptionSepArg,    NULL},
  488. X    {"-ebg",        "errorBack",        XrmoptionSepArg,    NULL},
  489. X    {"-efg",        "errorFore",        XrmoptionSepArg,    NULL},
  490. X    {"-ehl",        "errorHl",        XrmoptionSepArg,    NULL},
  491. X    {"-eibd",        "errorIbd",        XrmoptionSepArg,    NULL},
  492. X    {"-elevel",        "errorLevel",        XrmoptionSepArg,    NULL},
  493. X    {"-ep",        "errorProg",        XrmoptionSepArg,    NULL},
  494. X    {"-fbd",        "fatalBd",        XrmoptionSepArg,    NULL},
  495. X    {"-fbg",        "fatalBack",        XrmoptionSepArg,    NULL},
  496. X    {"-ffg",        "fatalFore",        XrmoptionSepArg,    NULL},
  497. X    {"-fhl",        "fatalHl",        XrmoptionSepArg,    NULL},
  498. X    {"-fibd",        "fatalIbd",        XrmoptionSepArg,    NULL},
  499. X    {"-fp",        "fatalProg",        XrmoptionSepArg,    NULL},
  500. X    {"-h",        "*Paned.height",    XrmoptionSepArg,    NULL},
  501. X    {"-lebg",        "lErrorBack",        XrmoptionSepArg,    NULL},
  502. X    {"-lefg",        "lErrorFore",        XrmoptionSepArg,    NULL},
  503. X    {"-lfbg",        "lFatalBack",        XrmoptionSepArg,    NULL},
  504. X    {"-lffg",        "lFatalFore",        XrmoptionSepArg,    NULL},
  505. X    {"-lobg",        "lOkBack",        XrmoptionSepArg,    NULL},
  506. X    {"-lofg",        "lOkFore",        XrmoptionSepArg,    NULL},
  507. X    {"-lwbg",        "lWarnBack",        XrmoptionSepArg,    NULL},
  508. X    {"-lwfg",        "lWarnFore",        XrmoptionSepArg,    NULL},
  509. X    {"-obd",        "okBd",            XrmoptionSepArg,    NULL},
  510. X    {"-obg",        "okBack",        XrmoptionSepArg,    NULL},
  511. X    {"-ofg",        "okFore",        XrmoptionSepArg,    NULL},
  512. X    {"-ohl",        "okHl",            XrmoptionSepArg,    NULL},
  513. X    {"-oibd",        "okIbd",        XrmoptionSepArg,    NULL},
  514. X    {"-op",        "okProg",        XrmoptionSepArg,    NULL},
  515. X    {"-rows",        "rows",            XrmoptionSepArg,    NULL},
  516. X    {"-rt",        "retries",        XrmoptionSepArg,    NULL},
  517. X    {"-scoll",        "scaleColl",        XrmoptionSepArg,    NULL},
  518. X    {"-scpu",        "scaleCpu",        XrmoptionSepArg,    NULL},
  519. X    {"-sierr",        "scaleIerr",        XrmoptionSepArg,    NULL},
  520. X    {"-sintr",        "scaleIntr",        XrmoptionSepArg,    NULL},
  521. X    {"-sipkt",        "scaleIpkt",        XrmoptionSepArg,    NULL},
  522. X    {"-sload",        "scaleLoad",        XrmoptionSepArg,    NULL},
  523. X    {"-sn",        "shortName",        XrmoptionNoArg,        "on"},
  524. X    {"-soerr",        "scaleOerr",        XrmoptionSepArg,    NULL},
  525. X    {"-sopkt",        "scaleOpkt",        XrmoptionSepArg,    NULL},
  526. X    {"-spage",        "scalePage",        XrmoptionSepArg,    NULL},
  527. X    {"-spgpgin",    "scalePgpgin",        XrmoptionSepArg,    NULL},
  528. X    {"-spgpgout",    "scalePgpgout",        XrmoptionSepArg,    NULL},
  529. X    {"-spswpin",    "scalePswpin",        XrmoptionSepArg,    NULL},
  530. X    {"-spswpout",    "scalePswpout",        XrmoptionSepArg,    NULL},
  531. X    {"-sswt",        "scaleSwt",        XrmoptionSepArg,    NULL},
  532. X    {"-ssys",        "scaleSys",        XrmoptionSepArg,    NULL},
  533. X    {"-suser",        "scaleUser",        XrmoptionSepArg,    NULL},
  534. X    {"-to",        "timeout",        XrmoptionSepArg,    NULL},
  535. X    {"-update",        "*StripChart.update",    XrmoptionSepArg,    NULL},
  536. X    {"-w",        "*Paned.width",        XrmoptionSepArg,    NULL},
  537. X    {"-wbd",        "warnBd",        XrmoptionSepArg,    NULL},
  538. X    {"-wbg",        "warnBack",        XrmoptionSepArg,    NULL},
  539. X    {"-wfg",        "warnFore",        XrmoptionSepArg,    NULL},
  540. X    {"-whl",        "warnHl",        XrmoptionSepArg,    NULL},
  541. X    {"-wibd",        "warnIbd",        XrmoptionSepArg,    NULL},
  542. X    {"-wlevel",        "warnLevel",        XrmoptionSepArg,    NULL},
  543. X    {"-wp",        "warnProg",        XrmoptionSepArg,    NULL},
  544. X};
  545. Xstatic Arg        formargs[] = {
  546. X    {XtNdefaultDistance,    1},        /* Spacing        */
  547. X    {XtNresizable,        TRUE },        /* Resizable        */
  548. X};
  549. X
  550. Xmain (argc, argv)
  551. X
  552. Xint    argc;
  553. Xchar    **argv;
  554. X
  555. X{
  556. X  Widget        toplevel;
  557. X  Widget        form;
  558. X  Widget        pane = NULL;
  559. X  int            i;
  560. X  int            n;
  561. X  Arg            args[10];
  562. X  XtAppContext        appcon;
  563. X  String        mbtrans =
  564. X      "<EnterWindow>:    highlight()\n\
  565. X       <LeaveWindow>:    reset()\n\
  566. X       <BtnDown>:    set() notify() PopupMenu()";
  567. X  XtTranslations    mbtt;
  568. X  Widget        *lw;    /* Last column or row of widgets    */
  569. X  int            numwgt;
  570. X
  571. X  progname = argv[0];
  572. X  toplevel = XtAppInitialize (&appcon, "XMeter", options,
  573. X        XtNumber (options), &argc, argv, NULL, NULL, ZERO);
  574. X  XtGetApplicationResources (toplevel, NULL, application_resources,
  575. X                 XtNumber (application_resources), NULL, 0);
  576. X  form = XtCreateManagedWidget ("form", formWidgetClass, toplevel,
  577. X                    formargs, XtNumber (formargs));
  578. X  if (argc < 2)
  579. X      usage ();
  580. X  if (strcmp ("-v", argv[1]) == 0)
  581. X       printversion ();
  582. X  init (toplevel, &lw);
  583. X  createmenus (form);
  584. X  mbtt = XtParseTranslationTable (mbtrans);
  585. X  /*
  586. X   * Each meter consists of a paned widget, each paned widget has two
  587. X   * children, which are a menubutton widget and stripchart widget.
  588. X   * The following loop creates and initializes the appropriate widgets.
  589. X   */
  590. X  for (i = 1, numwgt = 0; i < argc; i++, numwgt++) {
  591. X      meterlist = initmeter (meterlist, &i, argc, argv);
  592. X    /*
  593. X     * Create paned widget.
  594. X     */
  595. X      n = 0;
  596. X      if (columns > 0) {        /* Locate pane in form ...    */
  597. X      XtSetArg (args[n], XtNfromVert, lw[numwgt % columns]); n++;
  598. X      if (numwgt % columns != 0) {
  599. X          XtSetArg (args[n], XtNfromHoriz, pane); n++;
  600. X      }
  601. X      } else {
  602. X      XtSetArg (args[n], XtNfromHoriz, lw[numwgt % rows]); n++;
  603. X      if (numwgt % rows != 0) {
  604. X          XtSetArg (args[n], XtNfromVert, pane); n++;
  605. X      }
  606. X      }
  607. X      XtSetArg (args[n], XtNborder, bd[OK]); n++;
  608. X      XtSetArg (args[n], XtNinternalBorderColor, ibd[OK]); n++;
  609. X      pane = XtCreateManagedWidget (meterlist->sh->name, panedWidgetClass,
  610. X                    form, args, n);
  611. X      lw[numwgt % (columns > 0 ? columns : rows)] = pane;
  612. X      meterlist->pdwidget = pane;
  613. X    /*
  614. X     * Create menubutton widget.
  615. X     */
  616. X      n = 0;
  617. X      XtSetArg (args[n], XtNshowGrip, XtEno); n++;
  618. X      XtSetArg (args[n], XtNlabel, meterlist->label); n++;
  619. X      XtSetArg (args[n], XtNbackground, lback[OK]); n++;
  620. X      XtSetArg (args[n], XtNforeground, lfore[OK]); n++;
  621. X      XtSetArg (args[n], XtNmenuName, STATMENU); n++;
  622. X      XtSetArg (args[n], XtNtranslations, mbtt); n++;
  623. X      meterlist->mbwidget = XtCreateManagedWidget ("menu",
  624. X                menuButtonWidgetClass, pane, args, n);
  625. X      XtRemoveAllCallbacks (meterlist->mbwidget, XtNcallback);
  626. X      XtAddCallback (meterlist->mbwidget, XtNcallback, selecthost, meterlist);
  627. X    /*
  628. X     * Create stripchart widget.
  629. X     */
  630. X      n = 0;
  631. X      XtSetArg (args[n], XtNfromVert, meterlist->mbwidget); n++;
  632. X      XtSetArg (args[n], XtNresizable, TRUE); n++;
  633. X      XtSetArg (args[n], XtNbackground, back[OK]); n++;
  634. X      XtSetArg (args[n], XtNforeground, fore[OK]); n++;
  635. X      XtSetArg (args[n], XtNhighlight, hl[OK]); n++;
  636. X      meterlist->scwidget = XtCreateManagedWidget ("load",
  637. X                stripChartWidgetClass, pane, args, n);
  638. X      XtRemoveAllCallbacks (meterlist->scwidget, XtNgetValue);
  639. X      XtAddCallback (meterlist->scwidget, XtNgetValue, getstatus, meterlist);
  640. X  }
  641. X  free (lw);
  642. X  signal (SIGCHLD, freechild);        /* Clean up after our children    */
  643. X  XtRealizeWidget (toplevel);
  644. X  setokbackgrounds (XtDisplay (toplevel), XtScreen (toplevel));
  645. X  XtAppMainLoop (appcon);
  646. X}
  647. X
  648. Xusage ()
  649. X
  650. X{
  651. X  int    i;
  652. X
  653. X  fprintf (stderr, "Usage: %s [toolkit options] [options] [stat] host ...\n",
  654. X       progname);
  655. X  fprintf (stderr, "  Options are:");
  656. X  for (i = 0; i < XtNumber (options); i++) {
  657. X      if (i % 8 == 0)
  658. X          fprintf (stderr, "\n    ");
  659. X      else
  660. X      fprintf (stderr, ", ");
  661. X      fprintf (stderr, "%s", options[i].option);
  662. X  }
  663. X  fprintf (stderr, ", -v\n  Stats to watch are:");
  664. X  for (i = 0; i < MAXSTAT; i++) {
  665. X      if (i % 8 == 0)
  666. X          fprintf (stderr, "\n    ");
  667. X      else
  668. X      fprintf (stderr, ", ");
  669. X      fprintf (stderr, "-%s", sd[i].name);
  670. X  }
  671. X  fprintf (stderr, "\n");
  672. X  exit (1);
  673. X}
  674. X
  675. X/*
  676. X * printversion - Print version number and exit.
  677. X */
  678. Xprintversion ()
  679. X
  680. X{
  681. X  printf ("XMeter version %d.%d\n", MAJORVERSION, PATCHLEVEL);
  682. X  exit (0);
  683. X}
  684. X
  685. X/*
  686. X * init - Initialze various globals.
  687. X */
  688. Xinit (toplevel, lw)
  689. X
  690. XWidget    toplevel;
  691. XWidget    **lw;
  692. X
  693. X{
  694. X  int        i;
  695. X  Window    rw;
  696. X  int        x;
  697. X  int        y;
  698. X  int        bwidth;
  699. X  int        depth;
  700. X
  701. X  ptto.tv_sec = timeout;
  702. X  tto.tv_sec = timeout * retries;
  703. X  if (columns <= 0 && rows <= 0)
  704. X      columns = 1;
  705. X  if (columns > 0) {
  706. X      if ((*lw = (Widget *) calloc (columns, sizeof (Widget))) == NULL)    
  707. X      fatal ("lw");    
  708. X  } else
  709. X      if ((*lw = (Widget *) calloc (rows, sizeof (Widget))) == NULL)
  710. X      fatal ("lw");
  711. X  for (i = 0; i < MAXBACKS; i++)
  712. X      if (bitmap[i].bm != bitmapdef)    /* Get bitmap dimensions    */
  713. X      XGetGeometry (XtDisplay (toplevel), bitmap[i].bm, &rw, &x, &y,
  714. X            &bitmap[i].w, &bitmap[i].h, &bwidth, &depth);
  715. X}
  716. X
  717. X/*
  718. X * createmenus - Create menus used by each meter.  Currently there's just
  719. X *   one which consists of the stats that can be monitored.
  720. X */
  721. Xcreatemenus (parent)
  722. X
  723. XWidget    parent;
  724. X
  725. X{
  726. X  int        i;
  727. X  int        n;
  728. X  Widget    menu;
  729. X  Widget    me;
  730. X  Arg        args[10];
  731. X
  732. X  menu = XtCreatePopupShell (STATMENU, simpleMenuWidgetClass, parent,
  733. X                 NULL, ZERO);
  734. X  for (i = 0; i < MAXSTAT; i++) {
  735. X      n = 0;
  736. X      XtSetArg (args[n], XtNlabel, sd[i].name); n++;
  737. X      me = XtCreateManagedWidget (sd[i].name, smeBSBObjectClass, menu,
  738. X                  args, n);
  739. X      XtRemoveAllCallbacks (me, XtNcallback);
  740. X      XtAddCallback (me, XtNcallback, changestat, i);
  741. X  }
  742. X}
  743. X
  744. X/*
  745. X * setokbackgrounds - Set initial background pixmaps.  Can't do this
  746. X *   when the stripchart widgets are created as they have to be
  747. X *   realized apparently before the pixmaps can be created.
  748. X */
  749. Xsetokbackgrounds (d, s)
  750. X
  751. XDisplay    *d;
  752. XScreen    *s;
  753. X
  754. X{
  755. X  METER        *h;
  756. X  int        n;
  757. X  Arg        args[10];
  758. X
  759. X  if (bitmap[OK].bm != bitmapdef) {
  760. X      for (h = meterlist; h; h = h->nxt) {
  761. X      h->pm = XmuCreatePixmapFromBitmap (d, XtWindow (h->scwidget),
  762. X                         bitmap[OK].bm,
  763. X                         bitmap[OK].w, bitmap[OK].h,
  764. X                         DefaultDepthOfScreen (s),
  765. X                         fore[OK],
  766. X                         back[OK]);
  767. X      n = 0;
  768. X      XtSetArg (args[n], XtNbackgroundPixmap, h->pm); n++;
  769. X      XtSetValues (h->scwidget, args, n);
  770. X      }
  771. X  }
  772. X}
  773. X
  774. X/*
  775. X * freechild - Clean up child processes.
  776. X */
  777. Xfreechild ()
  778. X
  779. X{
  780. X  int    status;
  781. X  int    pid;
  782. X  METER    *h;
  783. X
  784. X  pid = wait (&status);
  785. X  for (h = meterlist; h; h = h->nxt)
  786. X      if (h->sh->pid == pid) {    /* Start updating host again    */
  787. X      h->sh->pid = -1;
  788. X      break;
  789. X      }
  790. X}
  791. X
  792. X/*
  793. X * getstatus - Get status from remote host, update meter appropriately,
  794. X *   including changing colors, background pixmap and label if necessary.
  795. X */
  796. Xgetstatus (w, h, data)
  797. X
  798. XWidget    w;
  799. XMETER    *h;
  800. Xchar    *data;
  801. X
  802. X{
  803. X  int            l;
  804. X  int            n;
  805. X  int            s;
  806. X  register SHMETER    *sh;
  807. X  Arg            args[10];
  808. X
  809. X  sh = h->sh;
  810. X  if (h->oldstate == FATAL && sh->pid != -1)    /* Ignore dead hosts    */
  811. X      return;
  812. X  if (h->oldjumpscroll) {        /* Restore old jumpscroll value    */
  813. X      n = 0;
  814. X      XtSetArg (args[n], XtNjumpScroll, h->oldjumpscroll); n++;
  815. X      XtSetValues (h->scwidget, args, n);
  816. X      h->oldjumpscroll = 0;
  817. X  }
  818. X  s = state (l = getmeter (h), h);
  819. X  *(double *) data = s == FATAL ? 0.0 : (double) l / sd[h->stat].scale;
  820. X  if (s != h->oldstate) {
  821. X      if (bitmap[h->oldstate].bm != bitmapdef)
  822. X      XFreePixmap (XtDisplay (w), h->pm);
  823. X      n = 0;                /* Update stripchart widget    */
  824. X      XtSetArg (args[n], XtNbackground, back[s]); n++;
  825. X      XtSetArg (args[n], XtNforeground, fore[s]); n++;
  826. X      XtSetArg (args[n], XtNhighlight, hl[s]); n++;
  827. X      if (bitmap[s].bm != bitmapdef) {
  828. X      h->pm = XmuCreatePixmapFromBitmap (XtDisplay (w),
  829. X                         XtWindow (w),
  830. X                         bitmap[s].bm,
  831. X                         bitmap[s].w, bitmap[s].h,
  832. X                         DefaultDepthOfScreen(XtScreen(w)),
  833. X                         fore[s],
  834. X                         back[s]);
  835. X      XtSetArg (args[n], XtNbackgroundPixmap, h->pm); n++;
  836. X      } else if (bitmap[h->oldstate].bm != bitmapdef) {
  837. X      XtSetArg (args[n], XtNbackgroundPixmap, XtUnspecifiedPixmap); n++;
  838. X      }
  839. X      XtSetValues (w, args, n);
  840. X      n = 0;                /* Update menubutton widget    */
  841. X      XtSetArg (args[n], XtNbackground, lback[s]); n++;
  842. X      XtSetArg (args[n], XtNforeground, lfore[s]); n++;
  843. X      if (s == FATAL || h->oldstate == FATAL) {
  844. X      sprintf (h->label, "%s %s", sh->name,
  845. X           s == FATAL ? DMSG : sd[h->stat].name);
  846. X      XtSetArg (args[n], XtNlabel, h->label); n++;
  847. X      }
  848. X      XtSetValues (h->mbwidget, args, n);
  849. X      n = 0;                /* Update paned widget        */
  850. X      XtSetArg (args[n], XtNborder, bd[s]); n++;
  851. X      XtSetArg (args[n], XtNinternalBorderColor, ibd[s]); n++;
  852. X      XtSetValues (h->pdwidget, args, n);
  853. X      if (prog[s])
  854. X      runprog (h, s);
  855. X      if (s == FATAL)
  856. X      sh->pid = waitforhost (h);
  857. X  }
  858. X  h->oldstate = s;
  859. X}
  860. X
  861. X/*
  862. X * waitforhost - Fork process which will wait for host to come back up.
  863. X */
  864. Xint waitforhost (h)
  865. X
  866. XMETER    *h;
  867. X
  868. X{
  869. X  int    pid;
  870. X
  871. X  if (pid = fork ())
  872. X      return (pid);
  873. X  while (1) {
  874. X      sleep (10);
  875. X      if (getport (h) >= 0)
  876. X      exit (0);
  877. X  }
  878. X}
  879. X
  880. X/*
  881. X * runprog - Run user specified alert program.
  882. X */
  883. Xrunprog (h, s)
  884. X
  885. XMETER    *h;
  886. Xint    s;
  887. X
  888. X{
  889. X  char    oldstate[4];
  890. X  char    state[4];
  891. X
  892. X  sprintf (oldstate, "%d", h->oldstate);
  893. X  sprintf (state, "%d", s);
  894. X  if (vfork ())
  895. X      return;            /* Parent just returns        */
  896. X  execlp (prog[s], prog[s], oldstate, state, h->sh->name, NULL);
  897. X  fatal (prog[s]);
  898. X}
  899. X
  900. X/*
  901. X * selecthost - Select host for next changestat().
  902. X */
  903. Xselecthost (w, h, data)
  904. X
  905. XWidget    w;
  906. XMETER    *h;
  907. Xchar    *data;
  908. X
  909. X{
  910. X  selected = h;
  911. X}
  912. X
  913. X/*
  914. X * changestat - Change statistic we're looking at.  To clear the stripchart
  915. X *   it's necessary to poke the "interval" field in the StripChartWidget
  916. X *   structure, and then set "jumpScroll" to the width of the stripchart.
  917. X *   jumpScroll is saved here and restored in getstatus().
  918. X */
  919. X#include <X11/IntrinsicP.h>
  920. X#include <X11/Xaw/StripCharP.h>
  921. Xchangestat (w, statidx, data)
  922. X
  923. XWidget    w;
  924. Xint    statidx;
  925. Xchar    *data;
  926. X
  927. X{
  928. X  int    n;
  929. X  Arg    args[10];
  930. X  int    width;
  931. X
  932. X  selected->stat = statidx;
  933. X  sprintf (selected->label, "%s %s", selected->sh->name,
  934. X       sd[statidx].name);
  935. X  n = 0;
  936. X  XtSetArg (args[n], XtNlabel, selected->label); n++;
  937. X  XtSetValues (selected->mbwidget, args, n);
  938. X  n = 0;
  939. X  XtSetArg (args[n], XtNwidth, &width); n++;
  940. X  XtSetArg (args[n], XtNjumpScroll, &selected->oldjumpscroll); n++;
  941. X  XtGetValues (selected->scwidget, args, n);
  942. X  n = 0;
  943. X  XtSetArg (args[n], XtNjumpScroll, width); n++;
  944. X  XtSetValues (selected->scwidget, args, n);
  945. X  ((StripChartWidget) selected->scwidget)->strip_chart.interval = width;
  946. X}
  947. X
  948. X/*
  949. X * state - Return state of current stat.
  950. X */
  951. Xint state (l, h)
  952. X
  953. Xint    l;
  954. XMETER    *h;
  955. X
  956. X{
  957. X  if (l < 0)
  958. X      return (FATAL);
  959. X  else if (l < warnLevel * sd[h->stat].scale)
  960. X      return (OK);
  961. X  else if (l < errorLevel * sd[h->stat].scale)
  962. X      return (WARN);
  963. X  else
  964. X      return (ERROR);
  965. X}
  966. X
  967. X/*
  968. X * The following functions return the value of the specified stat, which
  969. X * is normally computed by taking the difference between the current
  970. X * value and the previous value, and dividing by the update interval in
  971. X * order to get the current rate.
  972. X */
  973. X#define DIF(m,fld)    (m->sh->st[m->sh->idx].fld - \
  974. X             m->sh->st[m->sh->idx ^ 1].fld)
  975. X
  976. Xint fcoll (h)
  977. X
  978. XMETER    *h;
  979. X
  980. X{
  981. X  return (DIF (h, if_collisions) / DIF (h, curtime.tv_sec));
  982. X}
  983. X
  984. Xint fcpu (h)
  985. X
  986. XMETER    *h;
  987. X
  988. X{
  989. X  int    i;
  990. X  int    t;
  991. X  int    d[CPUSTATES];
  992. X
  993. X  for (t = 0, i= 0; i < CPUSTATES; i++)
  994. X      t += (d[i] = DIF (h, cp_time[i]));
  995. X  return (t ? (100 * (d[CP_USER]+d[CP_NICE]+d[CP_SYS])) / t : 0);
  996. X}
  997. X
  998. Xint fierr (h)
  999. X
  1000. XMETER    *h;
  1001. X
  1002. X{
  1003. X  return (DIF (h, if_ierrors) / DIF (h, curtime.tv_sec));
  1004. X}
  1005. X
  1006. Xint fintr (h)
  1007. X
  1008. XMETER    *h;
  1009. X
  1010. X{
  1011. X  return (DIF (h, v_intr) / DIF (h, curtime.tv_sec));
  1012. X}
  1013. X
  1014. Xint fipkt (h)
  1015. X
  1016. XMETER    *h;
  1017. X
  1018. X{
  1019. X  return (DIF (h, if_ipackets) / DIF (h, curtime.tv_sec));
  1020. X}
  1021. X
  1022. Xint fload (h)
  1023. X
  1024. XMETER    *h;
  1025. X
  1026. X{
  1027. X  return (h->sh->st[h->sh->idx].avenrun[0]);
  1028. X}
  1029. X
  1030. Xint foerr (h)
  1031. X
  1032. XMETER    *h;
  1033. X
  1034. X{
  1035. X  return (DIF (h, if_oerrors) / DIF (h, curtime.tv_sec));
  1036. X}
  1037. X
  1038. Xint fopkt (h)
  1039. X
  1040. XMETER    *h;
  1041. X
  1042. X{
  1043. X  return (DIF (h, if_opackets) / DIF (h, curtime.tv_sec));
  1044. X}
  1045. X
  1046. Xint fpage (h)
  1047. X
  1048. XMETER    *h;
  1049. X
  1050. X{
  1051. X  return ((DIF (h, v_pgpgin) + DIF (h, v_pgpgout)) / DIF (h, curtime.tv_sec));
  1052. X}
  1053. X
  1054. Xint fpgpgin (h)
  1055. X
  1056. XMETER    *h;
  1057. X
  1058. X{
  1059. X  return (DIF (h, v_pgpgin) / DIF (h, curtime.tv_sec));
  1060. X}
  1061. X
  1062. Xint fpgpgout (h)
  1063. X
  1064. XMETER    *h;
  1065. X
  1066. X{
  1067. X  return (DIF (h, v_pgpgout) / DIF (h, curtime.tv_sec));
  1068. X}
  1069. X
  1070. Xint  fpswpin (h)
  1071. X
  1072. XMETER    *h;
  1073. X
  1074. X{
  1075. X  return (DIF (h, v_pswpin) / DIF (h, curtime.tv_sec));
  1076. X}
  1077. X
  1078. Xint fpswpout (h)
  1079. X
  1080. XMETER    *h;
  1081. X
  1082. X{
  1083. X  return (DIF (h, v_pswpout) / DIF (h, curtime.tv_sec));
  1084. X}
  1085. X
  1086. Xint fswt (h)
  1087. X
  1088. XMETER    *h;
  1089. X
  1090. X{
  1091. X  return (DIF (h, v_swtch) / DIF (h, curtime.tv_sec));
  1092. X}
  1093. X
  1094. Xint fsys (h)
  1095. X
  1096. XMETER    *h;
  1097. X
  1098. X{
  1099. X  int    i;
  1100. X  int    t;
  1101. X  int    d[CPUSTATES];
  1102. X
  1103. X  for (t = 0, i= 0; i < CPUSTATES; i++)
  1104. X      t += (d[i] = DIF (h, cp_time[i]));
  1105. X  return (t ? (100 * d[CP_SYS]) / t : 0);
  1106. X}
  1107. X
  1108. Xint fuser (h)
  1109. X
  1110. XMETER    *h;
  1111. X
  1112. X{
  1113. X  int    i;
  1114. X  int    t;
  1115. X  int    d[CPUSTATES];
  1116. X
  1117. X  for (t = 0, i= 0; i < CPUSTATES; i++)
  1118. X      t += (d[i] = DIF (h, cp_time[i]));
  1119. X  return (t ? (100 * (d[CP_USER] + d[CP_NICE])) / t : 0);
  1120. X}
  1121. X
  1122. X/*
  1123. X * getmeter - Executes rstat(3) call to read statistics for specified host.
  1124. X *   I do all the rpc junk myself so that I have better control over timeouts
  1125. X *   than rstat(3) gives me.  If we're watching multiple stats
  1126. X *   on the same host I only do one rstat(3) call (refcnt and curcnt are
  1127. X *   used for this).
  1128. X */
  1129. Xint getmeter (h)
  1130. X
  1131. Xregister METER    *h;
  1132. X
  1133. X{
  1134. X  enum clnt_stat    cs;
  1135. X  register SHMETER    *sh;
  1136. X  int            p;
  1137. X
  1138. X  sh = h->sh;
  1139. X  if (sh->curcnt >= sh->refcnt)
  1140. X      sh->curcnt = 0;
  1141. X  if (!sh->curcnt++) {
  1142. X      if (sh->clnt == NULL) {
  1143. X          if ((p = getport (h)) < 0)
  1144. X          return (-1);
  1145. X      sh->addr.sin_port = htons (p);
  1146. X          sh->s = RPC_ANYSOCK;
  1147. X          if (!(sh->clnt = clntudp_create(&sh->addr, RSTATPROG, RSTATVERS_TIME,
  1148. X                      ptto, &sh->s)))
  1149. X          return (-1);
  1150. X      sh->first = 1;
  1151. X          sh->idx = 0;
  1152. X      } else {
  1153. X      sh->first = 0;
  1154. X      sh->idx ^= 1;
  1155. X      }
  1156. X      cs = clnt_call (sh->clnt, RSTATPROC_STATS, xdr_void, 0, xdr_statstime,
  1157. X              &sh->st[sh->idx], tto);
  1158. X      if (cs != RPC_SUCCESS) {
  1159. X          clnt_destroy (sh->clnt);
  1160. X      close (sh->s);    /* Some clnt_destroy's don't do this    */
  1161. X          sh->clnt = NULL;
  1162. X          return (-1);
  1163. X      }
  1164. X  }
  1165. X  return (sh->first ? 0 :
  1166. X              sh->clnt == NULL ? -1 : (sd[h->stat].val) (h));
  1167. X}
  1168. X
  1169. X/*
  1170. X * getport - Get port rstatd is listening on.
  1171. X */
  1172. Xint getport (h)
  1173. X
  1174. XMETER    *h;
  1175. X
  1176. X{
  1177. X  CLIENT        *c;
  1178. X  enum clnt_stat    cs;
  1179. X  static struct pmap    pm = {RSTATPROG, RSTATVERS_TIME, IPPROTO_UDP, 0};
  1180. X  short         p;
  1181. X  register SHMETER    *sh;
  1182. X
  1183. X  sh = h->sh;
  1184. X  sh->s = RPC_ANYSOCK;
  1185. X  sh->addr.sin_port = htons (PMAPPORT);
  1186. X  if (!(c = clntudp_create (&sh->addr, PMAPPROG, PMAPVERS, ptto, &sh->s)))
  1187. X      return (-1);
  1188. X  cs = clnt_call (c, PMAPPROC_GETPORT, xdr_pmap, &pm, xdr_u_short, &p, tto);
  1189. X  clnt_destroy (c);
  1190. X  close (sh->s);        /* Some clnt_destroy's don't do this    */
  1191. X  return (cs == RPC_SUCCESS ? p : -1);
  1192. X}
  1193. X
  1194. X/*
  1195. X * initmeter - Fill in METER and SHMETER structures for this stat.
  1196. X */
  1197. XMETER *initmeter (meterlist, idx, argc, argv)
  1198. X
  1199. XMETER    *meterlist;
  1200. Xint    *idx;
  1201. Xint    argc;
  1202. Xchar    **argv;
  1203. X
  1204. X{
  1205. X  register METER    *h;
  1206. X  register SHMETER    *sh;
  1207. X  struct hostent    *he;
  1208. X  int            i;
  1209. X  char            *cp;
  1210. X
  1211. X  /*
  1212. X   * Create and fill in METER struct.
  1213. X   */
  1214. X  if (!(h = (METER *) malloc (sizeof (METER))))
  1215. X      fatal ("METER");
  1216. X  h->nxt = meterlist;
  1217. X  cp = (argv[*idx][0] == '-') ? &argv[*idx][1] : defstat;
  1218. X  for (i = 0; i < MAXSTAT; i++)
  1219. X      if (strcmp (cp, sd[i].name) == 0) {
  1220. X      h->stat = i;
  1221. X      break;
  1222. X      }
  1223. X  if ((cp != defstat) && (++(*idx) == argc || i >= MAXSTAT))
  1224. X      usage ();
  1225. X  if ((he = gethostbyname (argv[*idx])) == NULL)
  1226. X       fatal (argv[*idx]);
  1227. X  if (shortname)
  1228. X      if (cp = index (he->h_name, '.'))
  1229. X          *cp = '\0';
  1230. X  if (!(h->label = malloc (strlen (he->h_name) + 2 + MAXSTATNAME)))
  1231. X      fatal ("label");
  1232. X  sprintf (h->label, "%s %s", he->h_name, sd[h->stat].name);
  1233. X  h->oldstate = OK;
  1234. X  h->oldjumpscroll = 0;
  1235. X  /*
  1236. X   * If we're already looking at this host then just point h->sh at
  1237. X   * existing structure and we're done.
  1238. X   */
  1239. X  for (sh = shmeters; sh; sh = sh->nxt)
  1240. X      if (strcmp (sh->name, he->h_name) == 0) {
  1241. X      h->sh = sh;
  1242. X      sh->refcnt++;        /* Count how many references    */
  1243. X      return (h);
  1244. X      }
  1245. X  /*
  1246. X   * Not looking at this host yet, create and fill in SHMETER struct.
  1247. X   */
  1248. X  if (!(sh = (SHMETER *) malloc (sizeof (SHMETER))))
  1249. X      fatal ("SHMETER");
  1250. X  sh->nxt = shmeters;    /* Save this struct in linked list    */
  1251. X  shmeters = sh;
  1252. X  h->sh = sh;
  1253. X  if (!(sh->name = malloc (strlen (he->h_name) + 1)))
  1254. X      fatal ("name");
  1255. X  strcpy (sh->name, he->h_name);
  1256. X  bcopy (he->h_addr, &sh->addr.sin_addr, he->h_length);
  1257. X  sh->addr.sin_family = AF_INET;
  1258. X  sh->clnt = NULL;
  1259. X  sh->refcnt = 1;
  1260. X  sh->curcnt = 0;
  1261. X  sh->pid = -1;
  1262. X  return (h);
  1263. X}
  1264. X
  1265. Xfatal (m)
  1266. X
  1267. Xchar    *m;
  1268. X
  1269. X{
  1270. X  perror (m);
  1271. X  exit (1);
  1272. X}
  1273. END_OF_FILE
  1274. if test 33499 -ne `wc -c <'xmeter.c'`; then
  1275.     echo shar: \"'xmeter.c'\" unpacked with wrong size!
  1276. fi
  1277. # end of 'xmeter.c'
  1278. fi
  1279. if test -f 'xmeter.man' -a "${1}" != "-c" ; then 
  1280.   echo shar: Will not clobber existing file \"'xmeter.man'\"
  1281. else
  1282. echo shar: Extracting \"'xmeter.man'\" \(14019 characters\)
  1283. sed "s/^X//" >'xmeter.man' <<'END_OF_FILE'
  1284. X.TH XMETER 1 "14 August 1989" "X Version 11"
  1285. X.SH NAME
  1286. Xxmeter - rstat display for X
  1287. X.SH SYNOPSIS
  1288. X.B xmeter
  1289. X[-\fItoolkitoption\fP ...] [-\fIoption\fP ...] [-\fIstat\fP] hosts ...
  1290. X.SH DESCRIPTION
  1291. X.I Xmeter 
  1292. Xdisplays a periodically updating histogram of the system statistics
  1293. Xgathered by rstat(3) for the specified hosts.  Meters can be
  1294. Xdisplayed in a vertical, horizontal or rectangular arrangement.  As
  1295. Xstatistics range between 4 user defineable levels (OK, WARN, ERROR
  1296. Xor FATAL), the background, foreground, highlight, border and internal
  1297. Xborder  colors and the background bitmap of each meter can be changed.
  1298. X.LP
  1299. X.I Xmeter
  1300. Xuses the StripChart widget of the Athena Widget Set to graph each
  1301. Xstatistic.  StripCharts automatically scale the graph as the value
  1302. Xvaries, by drawing a number of horizontal lines across the StripChart.
  1303. XEach line represents an increment of a user settable value.  For
  1304. Xexample, if the statistic being graphed is number of pages paged in
  1305. Xper second, and the scale is set to 10, then each horizontal line
  1306. Xwould represent 10 pages per second.  Each time a graph is updated,
  1307. X.I xmeter
  1308. Xwill examine the current value of the statistic and the current scale,
  1309. Xas the number of scale lines increases above
  1310. X.I wlevel
  1311. Xand
  1312. X.I elevel
  1313. Xthe background colors and bitmaps of each graph are modified as specified.
  1314. X.LP
  1315. XThe statistic being graphed may be modified while
  1316. X.I xmeter
  1317. Xis running by moving the mouse cursor into the label part of a graph,
  1318. Xclicking any mouse button, and sliding down to the desired stat.
  1319. X.SH OPTIONS
  1320. X.PP
  1321. X.I Xmeter
  1322. Xaccepts all of the standard X Toolkit command line options along with the 
  1323. Xfollowing additional options:
  1324. X.PP
  1325. X.TP 8
  1326. X.B \-cols \fIcols\fP
  1327. XThis option specifies the number of columns the meters should be
  1328. Xdisplayed in.  If both
  1329. X.I cols
  1330. Xand
  1331. X.I rows
  1332. Xare specified,
  1333. X.I cols
  1334. Xtakes precedence.  The default is 1 column.
  1335. X.PP
  1336. X.TP 8
  1337. X.B \-ebd \fIcolor\fP
  1338. XSet error level border color.
  1339. X.PP
  1340. X.TP 8
  1341. X.B \-ebg \fIcolor\fP
  1342. XSet error level background color.
  1343. X.PP
  1344. X.TP 8
  1345. X.B \-efg \fIcolor\fP
  1346. XSet error level foreground color.
  1347. X.PP
  1348. X.TP 8
  1349. X.B \-ehl \fIcolor\fP
  1350. XSet error level highlight color.
  1351. X.PP
  1352. X.TP 8
  1353. X.B \-eibd \fIcolor\fP
  1354. XSet error level internal border color.
  1355. X.PP
  1356. X.TP 8
  1357. X.B \-elevel \fIinteger\fP
  1358. XThis option specifies the level at which the background color is changed
  1359. Xto ebg.  The default is 6.
  1360. X.PP
  1361. X.TP 8
  1362. X.B \-ep \fIprogram\fP
  1363. X.I program
  1364. Xshould be the name of a program to be invoked when the meter enters the
  1365. Xerror state.
  1366. X.I program
  1367. Xwill be passed 3 arguments, oldstate, newstate and the hostname being
  1368. Xmonitored.  Oldstate and newstate will be integers ranging from 0 to
  1369. X3, corresponding to levels OK, WARN, ERROR and FATAL.
  1370. X.PP
  1371. X.TP 8
  1372. X.B \-fbd \fIcolor\fP
  1373. XSet fatal level border color.
  1374. X.PP
  1375. X.TP 8
  1376. X.B \-fbg \fIcolor\fP
  1377. XSet fatal level background color.
  1378. X.PP
  1379. X.TP 8
  1380. X.B \-ffg \fIcolor\fP
  1381. XSet fatal level foreground color.
  1382. X.PP
  1383. X.TP 8
  1384. X.B \-fhl \fIcolor\fP
  1385. XSet fatal level highlight color.
  1386. X.PP
  1387. X.TP 8
  1388. X.B \-fibd \fIcolor\fP
  1389. XSet fatal level internal border color.
  1390. X.PP
  1391. X.TP 8
  1392. X.B \-fp \fIprogram\fP
  1393. X.I program
  1394. Xshould be the name of a program to be invoked when the monitored host is
  1395. Xdown.
  1396. X.I program
  1397. Xwill be passed 3 arguments, oldstate, newstate and the hostname being
  1398. Xmonitored.  Oldstate and newstate will be integers ranging from 0 to
  1399. X3, corresponding to levels OK, WARN, ERROR and FATAL.
  1400. X.PP
  1401. X.TP 8
  1402. X.B \-h \fIpixels\fP
  1403. XThis option specifies the height of each chart
  1404. X.I xmeter
  1405. Xwill display.  The default is 80.
  1406. X.PP
  1407. X.TP 8
  1408. X.B \-lebg \fIcolor\fP
  1409. XSet error level background color in menubutton.
  1410. X.PP
  1411. X.TP 8
  1412. X.B \-lefg \fIcolor\fP
  1413. XSet error level foreground color in menubutton.
  1414. X.PP
  1415. X.TP 8
  1416. X.B \-lfbg \fIcolor\fP
  1417. XSet fatal level background color in menubutton.
  1418. X.PP
  1419. X.TP 8
  1420. X.B \-lffg \fIcolor\fP
  1421. XSet fatal level foreground color in menubutton.
  1422. X.PP
  1423. X.TP 8
  1424. X.B \-lobg \fIcolor\fP
  1425. XSet ok level background color in menubutton.
  1426. X.PP
  1427. X.TP 8
  1428. X.B \-lofg \fIcolor\fP
  1429. XSet ok level foreground color in menubutton.
  1430. X.PP
  1431. X.TP 8
  1432. X.B \-lwbg \fIcolor\fP
  1433. XSet warn level background color in menubutton.
  1434. X.PP
  1435. X.TP 8
  1436. X.B \-lwfg \fIcolor\fP
  1437. XSet warn level foreground color in menubutton.
  1438. X.PP
  1439. X.TP 8
  1440. X.B \-obd \fIcolor\fP
  1441. XSet ok level border color.
  1442. X.PP
  1443. X.TP 8
  1444. X.B \-obg \fIcolor\fP
  1445. XSet ok level background color.
  1446. X.PP
  1447. X.TP 8
  1448. X.B \-ofg \fIcolor\fP
  1449. XSet ok level foreground color.
  1450. X.PP
  1451. X.TP 8
  1452. X.B \-ohl \fIcolor\fP
  1453. XSet ok level highlight color.
  1454. X.PP
  1455. X.TP 8
  1456. X.B \-oibd \fIcolor\fP
  1457. XSet ok level internal border color.
  1458. X.PP
  1459. X.TP 8
  1460. X.B \-op \fIprogram\fP
  1461. X.I program
  1462. Xshould be the name of a program to be invoked when the meter enters WARN
  1463. Xstate.
  1464. X.I program
  1465. Xwill be passed 3 arguments, oldstate, newstate and the hostname being
  1466. Xmonitored.  Oldstate and newstate will be integers ranging from 0 to
  1467. X3, corresponding to levels OK, WARN, ERROR and FATAL.
  1468. X.PP
  1469. X.TP 8
  1470. X.B \-rows \fIrows\fP
  1471. XThis option specifies the number of rows the meters should be
  1472. Xdisplayed in.  If both
  1473. X.I cols
  1474. Xand
  1475. X.I rows
  1476. Xare specified,
  1477. X.I cols
  1478. Xtakes precedence.  The default is 1 column.
  1479. X.PP
  1480. X.TP 8
  1481. X.B \-rt \fIretries\fP
  1482. XThis option specifies the number of times to retry failed RPC calls.
  1483. XThe default is 2.
  1484. X.PP
  1485. X.TP 8
  1486. X.B \-scoll \fIinteger\fP
  1487. XSet scale for collisions.  The default is 1.
  1488. X.PP
  1489. X.TP 8
  1490. X.B \-scpu \fIinteger\fP
  1491. XSet scale for cpu time.  The default is 20.
  1492. X.PP
  1493. X.TP 8
  1494. X.B \-sierr \fIinteger\fP
  1495. XSet scale for input errors.  The default is 1.
  1496. X.PP
  1497. X.TP 8
  1498. X.B \-sintr \fIinteger\fP
  1499. XSet scale for interrupts.  The default is 50.
  1500. X.PP
  1501. X.TP 8
  1502. X.B \-sipkt \fIinteger\fP
  1503. XSet scale for input packets.  The default is 20.
  1504. X.PP
  1505. X.TP 8
  1506. X.B \-sload \fIinteger\fP
  1507. XSet scale for load average.  The default is FSCALE (see param.h).
  1508. X.PP
  1509. X.TP 8
  1510. X.B \-sn
  1511. XIf specified strips off domain part of host name in menubuttons.
  1512. X.PP
  1513. X.TP 8
  1514. X.B \-soerr \fIinteger\fP
  1515. XSet scale for output errors.  The default is 1.
  1516. X.PP
  1517. X.TP 8
  1518. X.B \-sopkt \fIinteger\fP
  1519. XSet scale for output packets.  The default is 20.
  1520. X.PP
  1521. X.TP 8
  1522. X.B \-spage \fIinteger\fP
  1523. XSet scale for pages paged in and out.  The default is 10.
  1524. X.PP
  1525. X.TP 8
  1526. X.B \-spgpgin \fIinteger\fP
  1527. XSet scale for pages paged in.  The default is 10.
  1528. X.PP
  1529. X.TP 8
  1530. X.B \-spgpgout \fIinteger\fP
  1531. XSet scale for pages paged out.  The default is 10.
  1532. X.PP
  1533. X.TP 8
  1534. X.B \-spswpin \fIinteger\fP
  1535. XSet scale for pages swapped in.  The default is 1.
  1536. X.PP
  1537. X.TP 8
  1538. X.B \-spswpout \fIinteger\fP
  1539. XSet scale for pages swapped out.  The default is 1.
  1540. X.PP
  1541. X.TP 8
  1542. X.B \-sswt \fIinteger\fP
  1543. XSet scale for context switches.  The default is 30.
  1544. X.PP
  1545. X.TP 8
  1546. X.B \-ssys \fIinteger\fP
  1547. XSet scale for sys time.  The default is 20.
  1548. X.PP
  1549. X.TP 8
  1550. X.B \-suser \fIinteger\fP
  1551. XSet scale for user time.  The default is 20.
  1552. X.PP
  1553. X.TP 8
  1554. X.B \-to \fIseconds\fP
  1555. XThis option specifies the timeout for RPC calls.  The default is 5 seconds.
  1556. X.PP
  1557. X.TP 8
  1558. X.B \-update \fIseconds\fP
  1559. XThis option specifies the frequency in seconds at which
  1560. X.I xmeter
  1561. Xupdates its display.  The minimum amount of time allowed between updates
  1562. Xis 5 seconds.  The default is 60 seconds.
  1563. X.PP
  1564. X.TP 8
  1565. X.B \-v
  1566. XPrint version number and exit.
  1567. X.PP
  1568. X.TP 8
  1569. X.B \-w \fIpixels\fP
  1570. XThis option specifies the width of each chart
  1571. X.I xmeter
  1572. Xwill display.  The default is 80.
  1573. X.PP
  1574. X.TP 8
  1575. X.B \-wbd \fIcolor\fP
  1576. XSet warn level border color.
  1577. X.PP
  1578. X.TP 8
  1579. X.B \-wbg \fIcolor\fP
  1580. XSet warn level background color.
  1581. X.PP
  1582. X.TP 8
  1583. X.B \-wfg \fIcolor\fP
  1584. XSet warn level foreground color.
  1585. X.PP
  1586. X.TP 8
  1587. X.B \-whl \fIcolor\fP
  1588. XSet warn level highlight color.
  1589. X.PP
  1590. X.TP 8
  1591. X.B \-wibd \fIcolor\fP
  1592. XSet warn level internal border color.
  1593. X.PP
  1594. X.TP 8
  1595. X.B \-wlevel \fIinteger\fP
  1596. XThis option specifies the level at which the background color is changed
  1597. Xto wbg.  The default is 3.
  1598. X.PP
  1599. X.TP 8
  1600. X.B \-wp \fIprogram\fP
  1601. X.I program
  1602. Xshould be the name of a program to be invoked when the meter enters
  1603. XWARN state.
  1604. X.I program
  1605. Xwill be passed 3 arguments, oldstate, newstate and the hostname being
  1606. Xmonitored.  Oldstate and newstate will be integers ranging from 0 to
  1607. X3, corresponding to levels OK, WARN, ERROR and FATAL.
  1608. X.SH STATISTICS
  1609. X.PP
  1610. X.TP 8
  1611. X.B \-coll
  1612. XGraph number of collisions per second.
  1613. X.PP
  1614. X.TP 8
  1615. X.B \-cpu
  1616. XGraph percentage of non idle time for the specified host.
  1617. X.PP
  1618. X.TP 8
  1619. X.B \-ierr
  1620. XGraph number of input errors per second.
  1621. X.PP
  1622. X.TP 8
  1623. X.B \-intr
  1624. XGraph number of interrupts per second.
  1625. X.PP
  1626. X.TP 8
  1627. X.B \-ipkt
  1628. XGraph number of input packets per second.
  1629. X.PP
  1630. X.TP 8
  1631. X.B \-load
  1632. XGraph 1 minute load average.
  1633. X.PP
  1634. X.TP 8
  1635. X.B \-oerr
  1636. XGraph number of output errors per second.
  1637. X.PP
  1638. X.TP 8
  1639. X.B \-opkt
  1640. XGraph number of output packets per second.
  1641. X.PP
  1642. X.TP 8
  1643. X.B \-page
  1644. XSum of pgpgin and pgpgout values.
  1645. X.PP
  1646. X.TP 8
  1647. X.B \-pgpgin
  1648. XGraph number of pages paged in per second.
  1649. X.PP
  1650. X.TP 8
  1651. X.B \-pgpgout
  1652. XGraph number of pages paged out per second.
  1653. X.PP
  1654. X.TP 8
  1655. X.B \-pswpin
  1656. XGraph number of swapins per second.
  1657. X.PP
  1658. X.TP 8
  1659. X.B \-pswpout
  1660. XGraph number of swapouts per second.
  1661. X.PP
  1662. X.TP 8
  1663. X.B \-swt
  1664. XGraph number of context switches per second.
  1665. X.PP
  1666. X.TP 8
  1667. X.B \-sys
  1668. XGraph percentage of system time for the specified host.
  1669. X.PP
  1670. X.TP 8
  1671. X.B \-user
  1672. XGraph percentage of user time for the specified host.
  1673. X.SH "WIDGET HIERARCHY"
  1674. XThe widget hierarchy for
  1675. X.I xmeter
  1676. Xis given below.  Class names are given first, followed by instance
  1677. Xnames.
  1678. X.sp
  1679. X.nf
  1680. XXMeter xmeter
  1681. X    Form form
  1682. X        SimpleMenu statmenu
  1683. X            SmeBSB <stat>
  1684. X        Paned <hostname>
  1685. X            MenuButton menu
  1686. X            StripChart load
  1687. X.SH "RESOURCES"
  1688. XThe following resources are defined.  Resource instance names
  1689. Xare specified first, followed by class name.
  1690. X.PP
  1691. X.TP 8
  1692. X.B columns Columns
  1693. XSet number of columns of display.
  1694. X.PP
  1695. X.TP 8
  1696. X.B defStat DefStat
  1697. XDefault statistic to graph, the default is \fBload\fP.
  1698. X.PP
  1699. X.TP 8
  1700. X.B errorBack Background
  1701. XError level background color.
  1702. X.PP
  1703. X.TP 8
  1704. X.B errorBd Foreground
  1705. XError level border color.
  1706. X.PP
  1707. X.TP 8
  1708. X.B errorBitmap Bitmap
  1709. XError level background bitmap.
  1710. X.PP
  1711. X.TP 8
  1712. X.B errorFore Foreground
  1713. XError level foreground color.
  1714. X.PP
  1715. X.TP 8
  1716. X.B errorHl Foreground
  1717. XError level highlight color.
  1718. X.PP
  1719. X.TP 8
  1720. X.B errorIbd Foreground
  1721. XError level internal border color.
  1722. X.PP
  1723. X.TP 8
  1724. X.B errorLevel ErrorLevel
  1725. XWhen a statistic is above this value colors and bitmaps are
  1726. Xset to the appropriate error level value.
  1727. X.PP
  1728. X.TP 8
  1729. X.B errorProg Program
  1730. XProgram to be invoked when a meter enters error state.
  1731. X.PP
  1732. X.TP 8
  1733. X.B fatalBack Background
  1734. XBackground color of dead hosts.
  1735. X.PP
  1736. X.TP 8
  1737. X.B fatalBd Foreground
  1738. XBorder color of dead hosts.
  1739. X.PP
  1740. X.TP 8
  1741. X.B fatalBitmap Bitmap
  1742. XBackground bitmap of dead hosts.
  1743. X.PP
  1744. X.TP 8
  1745. X.B fatalFore Foreground
  1746. XForeground color of dead hosts.
  1747. X.PP
  1748. X.TP 8
  1749. X.B fatalHl Foreground
  1750. XHighlight color of dead hosts.
  1751. X.PP
  1752. X.TP 8
  1753. X.B fatalIbd Foreground
  1754. XInternal border color of dead hosts.
  1755. X.PP
  1756. X.TP 8
  1757. X.B fatalProg Program
  1758. XProgram to be invoked when a meter enters fatal state.
  1759. X.PP
  1760. X.TP 8
  1761. X.B lErrorBack Background
  1762. XError level background color of menubutton widget.
  1763. X.PP
  1764. X.TP 8
  1765. X.B lErrorFore Foreground
  1766. XError level foreground color of menubutton widget.
  1767. X.PP
  1768. X.TP 8
  1769. X.B lFatalBack Background
  1770. XFatal level background color of menubutton widget.
  1771. X.PP
  1772. X.TP 8
  1773. X.B lFatalFore Foreground
  1774. XFatal level foreground color of menubutton widget.
  1775. X.PP
  1776. X.TP 8
  1777. X.B lOkBack Background
  1778. XOk level background color of menubutton widget.
  1779. X.PP
  1780. X.TP 8
  1781. X.B lOkFore Foreground
  1782. XOk level foreground color of menubutton widget.
  1783. X.PP
  1784. X.TP 8
  1785. X.B lWarnBack Background
  1786. XWarn level background color of menubutton widget.
  1787. X.PP
  1788. X.TP 8
  1789. X.B lWarnFore Foreground
  1790. XWarn level foreground color of menubutton widget.
  1791. X.PP
  1792. X.TP 8
  1793. X.B okBack Background
  1794. XOk level background color.
  1795. X.PP
  1796. X.TP 8
  1797. X.B okBd Foreground
  1798. XOk level border color.
  1799. X.PP
  1800. X.TP 8
  1801. X.B okBitmap Bitmap
  1802. XOk level background bitmap.
  1803. X.PP
  1804. X.TP 8
  1805. X.B okFore Foreground
  1806. XOk level foreground color.
  1807. X.PP
  1808. X.TP 8
  1809. X.B okHl Foreground
  1810. XOk level highlight color.
  1811. X.PP
  1812. X.TP 8
  1813. X.B okIbd Foreground
  1814. XOk level internal border color.
  1815. X.PP
  1816. X.TP 8
  1817. X.B okProg Program
  1818. XProgram to be invoked when a meter enters ok state.
  1819. X.PP
  1820. X.TP 8
  1821. X.B retries Retries
  1822. XNumber of retries for RPC calls.
  1823. X.PP
  1824. X.TP 8
  1825. X.B rows Rows
  1826. XNumber of rows to display.
  1827. X.PP
  1828. X.TP 8
  1829. X.B scaleColl ScaleColl
  1830. XScale for interface collisions.
  1831. X.PP
  1832. X.TP 8
  1833. X.B scaleCpu ScaleCpu
  1834. XScale for percentage cpu usage.
  1835. X.PP
  1836. X.TP 8
  1837. X.B scaleIerr ScaleIerr
  1838. XScale for interface input errors.
  1839. X.PP
  1840. X.TP 8
  1841. X.B scaleIerr ScaleIntr
  1842. XScale for interface interrupts.
  1843. X.PP
  1844. X.TP 8
  1845. X.B scaleIpkt ScaleIpkt
  1846. XScale for interface input packets.
  1847. X.PP
  1848. X.TP 8
  1849. X.B scaleLoad ScaleLoad
  1850. XScale for load average.
  1851. X.PP
  1852. X.TP 8
  1853. X.B scaleOerr ScaleOerr
  1854. XScale for interface output errors.
  1855. X.PP
  1856. X.TP 8
  1857. X.B scaleOpkt ScaleOpkt
  1858. XScale for interface output packets.
  1859. X.PP
  1860. X.TP 8
  1861. X.B scalePage ScalePage
  1862. XScale for paging (sum of pageins and pageouts).
  1863. X.PP
  1864. X.TP 8
  1865. X.B scalePgpgin ScalePgpgin
  1866. XScale for pages paged in.
  1867. X.PP
  1868. X.TP 8
  1869. X.B scalePgpgout ScalePgpgout
  1870. XScale for pages paged out.
  1871. X.PP
  1872. X.TP 8
  1873. X.B scalePswpin ScalePswpin
  1874. XScale for swap ins.
  1875. X.PP
  1876. X.TP 8
  1877. X.B scalePswpout ScalePswpout
  1878. XScale for swap outs.
  1879. X.PP
  1880. X.TP 8
  1881. X.B scaleSwt ScaleSwt
  1882. XScale for context switches.
  1883. X.PP
  1884. X.TP 8
  1885. X.B scaleSys ScaleSys
  1886. XScale for percentage system time.
  1887. X.PP
  1888. X.TP 8
  1889. X.B scaleUser ScaleUser
  1890. XScale for percentage user time.
  1891. X.PP
  1892. X.TP 8
  1893. X.B shortName ShortName
  1894. XTrim domains off host names.
  1895. X.PP
  1896. X.TP 8
  1897. X.B timeout Timeout
  1898. XTimeout for RPC calls.
  1899. X.PP
  1900. X.TP 8
  1901. X.B update Interval
  1902. XInterval between updates.
  1903. X.PP
  1904. X.TP 8
  1905. X.B warnBack Background
  1906. XWarn level background color.
  1907. X.PP
  1908. X.TP 8
  1909. X.B warnBd Foreground
  1910. XWarn level border color.
  1911. X.PP
  1912. X.TP 8
  1913. X.B warnBitmap Bitmap
  1914. XWarn level Background bitmap.
  1915. Xbelow ErrorLevel.
  1916. X.PP
  1917. X.TP 8
  1918. X.B warnFore Foreground
  1919. XWarn level foreground color.
  1920. X.PP
  1921. X.TP 8
  1922. X.B warnHl Foreground
  1923. XWarn level highlight color.
  1924. X.PP
  1925. X.TP 8
  1926. X.B warnIbd Foreground
  1927. XWarn level internal border.
  1928. X.PP
  1929. X.TP 8
  1930. X.B warnLevel WarnLevel
  1931. XWhen statistic is above this level and below ErrorLevel background colors
  1932. Xand bitmaps are set to WarnBack and WarnBitmap.
  1933. X.PP
  1934. X.TP 8
  1935. X.B warnProg Program
  1936. XProgram to be invoked when a meter enters warn state.
  1937. X.SH BUGS
  1938. XWhen a host doesn't respond it can sometimes take awhile for the labels
  1939. Xin the menubuttons to update.
  1940. X.LP
  1941. XIf a height for the meters is specified but not a width, the error
  1942. X"Widget has zero width and/or height" is printed by the X toolkit.
  1943. XThe converse is not true.  I suspect the problem is in the Paned
  1944. Xwidget but xmeter could be doing something wrong.  The supplied
  1945. Xapplication defaults file initializes both width and height, as long
  1946. Xas this is installed there shouldn't be a problem unless the user
  1947. Xexplicitly sets width to 0.
  1948. X.SH AUTHOR
  1949. XBob Schwartzkopf, The RAND Corporation.  Based on xload from MIT.
  1950. END_OF_FILE
  1951. if test 14019 -ne `wc -c <'xmeter.man'`; then
  1952.     echo shar: \"'xmeter.man'\" unpacked with wrong size!
  1953. fi
  1954. # end of 'xmeter.man'
  1955. fi
  1956. if test -f 'XMeter.ad' -a "${1}" != "-c" ; then 
  1957.   echo shar: Will not clobber existing file \"'XMeter.ad'\"
  1958. else
  1959. echo shar: Extracting \"'XMeter.ad'\" \(80 characters\)
  1960. sed "s/^X//" >'XMeter.ad' <<'END_OF_FILE'
  1961. XXMeter*Paned.Width:        80
  1962. XXMeter*Paned.Height:        80
  1963. XXMeter*StripChart.Interval:    60
  1964. END_OF_FILE
  1965. if test 80 -ne `wc -c <'XMeter.ad'`; then
  1966.     echo shar: \"'XMeter.ad'\" unpacked with wrong size!
  1967. fi
  1968. # end of 'XMeter.ad'
  1969. fi
  1970. echo shar: End of shell archive.
  1971. exit 0
  1972.  
  1973.  
  1974. --
  1975. Dan Heller
  1976. O'Reilly && Associates       Z-Code Software    Comp-sources-x:
  1977. Senior Writer                President          comp-sources-x@uunet.uu.net
  1978. argv@ora.com                 argv@zipcode.com
  1979.